package com.dlc.shop.delivery.api.listener;

import cn.binarywang.wx.miniapp.bean.shop.request.shipping.PayerBean;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.dlc.shop.bean.event.AppConnectEvent;
import com.dlc.shop.security.common.model.AppConnect;
import com.dlc.shop.security.common.service.AppConnectService;
import lombok.AllArgsConstructor;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

/**
 * 获取第三方userid
 * @author yami
 */
@Component("AppconnectListener")
@AllArgsConstructor
public class AppconnectListener {

    private final AppConnectService appConnectService;

    @EventListener(AppConnectEvent.class)
    public void defaultEsProductListener(AppConnectEvent event) {
        String userId = event.getUserId();
        PayerBean payerBean = event.getPayerBean();
        AppConnect appConnect = appConnectService.getOne(new LambdaQueryWrapper<AppConnect>().eq(AppConnect::getUserId, userId));
        payerBean.setOpenid(appConnect.getBizUserId());
    }
}
